/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taxisluzba;

import dbaccess.Database;
import dbaccess.DatabaseConnectException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;

/**
 *
 * @author Majko
 */
public class AdministratorFrame extends javax.swing.JFrame {

    /**
     * Creates new form AdministratorFrame
     */
    public AdministratorFrame() {
        initComponents();
        naplnitTaxikarov();
        naplnitZakazky();
        naplnitDispecerov();
        naplnitVozidla();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable4 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jTextField4 = new javax.swing.JTextField();
        jButton12 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Meno", "Priezvisko", "Telefon", "Plat", "Bydlisko"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jLabel1.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel1.setText("Zamestnanci:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Taxikari:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Dispeceri:");

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Meno", "Priezvisko", "Bydlisko", "Adresa", "Telefon"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jLabel4.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel4.setText("Zakazky:");

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "ID", "Taxikar", "Start", "Ciel", "Vzdialenost", "Celk. vzdialenost", "Cena"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTable3);

        jLabel5.setFont(new java.awt.Font("Arial Unicode MS", 1, 12)); // NOI18N
        jLabel5.setText("Vozidla:");

        jTable4.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "SPZ", "Znacka", "Rok vyroby", "Najazdene kilometre", "Spotreba"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane4.setViewportView(jTable4);

        jButton1.setText("Pridat Taxikara");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Odobrat Taxikara");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField1.setText("Priezvisko");
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton3.setText("Hladat");

        jButton4.setText("Pridat Dispecera");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Odobrat Dispecera");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jTextField2.setText("Priezvisko");

        jButton6.setText("Hladat");

        jButton7.setText("Pridat Zakazku");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("Odobrat Zakazku");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jTextField3.setText("ID");

        jButton9.setText("Hladaj");

        jButton10.setText("Pridat Vozidlo");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setText("Odobrat Vozidlo");

        jTextField4.setText("Znacka");

        jButton12.setText("Hladaj");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(13, 13, 13)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6))
                    .addComponent(jScrollPane2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addComponent(jScrollPane4)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton9))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton12)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton2)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton3)
                        .addComponent(jButton7)
                        .addComponent(jButton8)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton9))
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addGap(15, 15, 15)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6)
                    .addComponent(jButton10)
                    .addComponent(jButton11)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        new PridatTaxikaraDialog(this,true).setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
       new PridatZakazkuDialog(this,true).setVisible(true); // TODO add your handling code here:
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        new PridatDispeceraDialog(this,true).setVisible(true);// TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
       new PridatVozidloDialog(this,true).setVisible(true); // TODO add your handling code here:
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        if(jTable1.isRowSelected(jTable1.getSelectedRow())){
            
            String tId=jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
            Database database = new Database();
            try {
                database.connect();
                database.deleteFromTaxikar(tId);
            } catch (DatabaseConnectException ex) {
                Logger.getLogger(AdministratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                database.disconnect();
            } catch (DatabaseConnectException ex) {
                Logger.getLogger(AdministratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        deleteTable(jTable1);
        naplnitTaxikarov();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        
        if(jTable3.isRowSelected(jTable3.getSelectedRow())){
            
            String tId=jTable3.getValueAt(jTable3.getSelectedRow(), 0).toString();
            Database database = new Database();
            try {
                database.connect();
                database.deleteFromZakazka(tId);
            } catch (DatabaseConnectException ex) {
                Logger.getLogger(AdministratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                database.disconnect();
            } catch (DatabaseConnectException ex) {
                Logger.getLogger(AdministratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        deleteTable(jTable3);
        naplnitZakazky();
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        if(jTable2.isRowSelected(jTable2.getSelectedRow())){
            
            String tId=jTable2.getValueAt(jTable2.getSelectedRow(), 0).toString();
            Database database = new Database();
            try {
                database.connect();
                database.deleteFromDispecer(tId);
            } catch (DatabaseConnectException ex) {
                Logger.getLogger(AdministratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                database.disconnect();
            } catch (DatabaseConnectException ex) {
                Logger.getLogger(AdministratorFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        deleteTable(jTable2);
        naplnitDispecerov();        // TODO add your handling code here:
    }//GEN-LAST:event_jButton5ActionPerformed
    
    public void naplnitTaxikarov(){
       Database database = new Database();
       
        try {
            database.connect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
       ResultSet rs = null;
       int i = 0;
       int j = 0;
       int k = 0;
       int l = 0;
       int m = 0;
       int n = 0;
       
        try {
            rs = database.selectFromTaxikarForAdministrator();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (rs.next()){
                jTable1.setValueAt(rs.getString(1), i++, 0);
                jTable1.setValueAt(rs.getString(2), j++, 1);
                jTable1.setValueAt(rs.getString(3), k++, 2);
                jTable1.setValueAt(rs.getString(4), l++, 3);
                jTable1.setValueAt(rs.getString(5), m++, 4);
                jTable1.setValueAt(rs.getString(6), n++, 5);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            database.disconnect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void naplnitDispecerov(){
       Database database = new Database();
       
        try {
            database.connect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
       ResultSet rs = null;
       int i = 0;
       int j = 0;
       int k = 0;
       int l = 0;
       int m = 0;
       int n = 0;
       
        try {
            rs = database.selectFromDispecer();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (rs.next()){
                jTable2.setValueAt(rs.getString(1), i++, 0);
                jTable2.setValueAt(rs.getString(2), j++, 1);
                jTable2.setValueAt(rs.getString(3), k++, 2);
                jTable2.setValueAt(rs.getString(4), l++, 3);
                jTable2.setValueAt(rs.getString(5), m++, 4);
                jTable2.setValueAt(rs.getString(6), n++, 5);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            database.disconnect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void naplnitVozidla(){
       Database database = new Database();
       
        try {
            database.connect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
       ResultSet rs = null;
       int i = 0;
       int j = 0;
       int k = 0;
       int l = 0;
       int m = 0;
       int n = 0;
       
        try {
            rs = database.selectFromVozidlo();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (rs.next()){
                jTable4.setValueAt(rs.getString(1), i++, 0);
                jTable4.setValueAt(rs.getString(2), j++, 1);
                jTable4.setValueAt(rs.getString(3), k++, 2);
                jTable4.setValueAt(rs.getString(4), l++, 3);
                jTable4.setValueAt(rs.getString(5), m++, 4);
             }
        } catch (SQLException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            database.disconnect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void naplnitZakazky(){
       Database database = new Database();
       
        try {
            database.connect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
       ResultSet rs = null;
       int i = 0;
       int j = 0;
       int k = 0;
       int l = 0;
       int m = 0;
       int n = 0;
       int o = 0;
       
        try {
            rs = database.selectFromZakazka();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (rs.next()){
                jTable3.setValueAt(rs.getString(1), i++, 0);
                jTable3.setValueAt(rs.getString(2), j++, 1);
                jTable3.setValueAt(rs.getString(3), k++, 2);
                jTable3.setValueAt(rs.getString(4), l++, 3);
                jTable3.setValueAt(rs.getString(5), m++, 4);
                jTable3.setValueAt(rs.getString(6), n++, 5);
                jTable3.setValueAt(rs.getString(7), o++, 6);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            database.disconnect();
        } catch (DatabaseConnectException ex) {
            Logger.getLogger(DispecerFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
    public void deleteTable(JTable tbl) {
        
        JTable table = tbl;
        
        for (int i = 0; i < table.getModel().getRowCount(); i++) {
            for (int j = 0; j < table.getModel().getColumnCount(); j++) {
                table.getModel().setValueAt(null, i, j);
            }
        }
    }
    public JTable getJTable1(){
        return jTable1;
    }
    public JTable getJTable2(){
        return jTable2;
    }
    public JTable getJTable3(){
        return jTable3;
    }
    public JTable getJTable4(){
        return jTable4;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTable jTable4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    // End of variables declaration//GEN-END:variables
}
